package com.yuwei.http

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

private val client by lazy {
    OkHttpClient.Builder()
        .callTimeout(5,TimeUnit.SECONDS)
        .readTimeout(5,TimeUnit.SECONDS)
        .writeTimeout(5,TimeUnit.SECONDS)
        .addInterceptor(TokenInterceptor())
        .addInterceptor(AccessIdInterceptor())
        .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
        .build()
}
val retrofit by lazy {
    Retrofit.Builder()
        .baseUrl(Const.BASE_URL)
        .client(client)
        .addConverterFactory(GsonConverterFactory.create())
        .build()
}
inline fun <reified T> getService() = retrofit.create(T :: class.java)
